var gulp = require("gulp");
var watch = require("gulp-watch");
var scss = require("gulp-sass");
var minifyCss = require("gulp-minify-css");
var connect = require("gulp-connect");
var fileinclude = require("gulp-file-include");

gulp.task("connect", function () {
  connect.server({
    livereload: true,
    port: 9909,
    host: "0.0.0.0",
  });
});

gulp.task("scss", function () {
  return gulp
    .src("src/scss/*.scss")
    .pipe(scss())
    .pipe(minifyCss())
    .pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());
});

gulp.task("demo", function () {
  return gulp
    .src("src/demo/*.html")
    .pipe(
      fileinclude({
        prefix: "@@",
        basepath: "@file",
      })
    )
    .pipe(gulp.dest("dist/demo"))
    .pipe(connect.reload());
});

gulp.task("watch", function () {
  gulp.watch("src/scss/*.scss", gulp.series("scss"));
  gulp.watch("src/demo/*.html", gulp.series("demo"));
});

gulp.task(
  "default",
  gulp.series(gulp.parallel("connect", "watch", "scss", "demo"))
);
